package linearsearch;

import java.util.Objects;

public enum LinearSearch {
    INSTANCE;

    public <E> int search(E[] arr, E target) {

        for (int i = 0; i < arr.length; i++) {
            //确定arr[i]是否是目标，arr[0,i)中没有找到目标
            if (Objects.equals(arr[i], target)) {//循环体：维持循环不变量
                return i;
            }
            //arr[i]不是目标
        }
        return -1;
    }

    public static void main(String[] args) {
        String[] data = {"24", "18", "12", "9", "16", "66", "32", "4"};
        LinearSearch.INSTANCE.search(data, "4");

    }
}
